<template>
	<el-form label-width="130px" :model="form" :rules="rules" ref="queryForm">
		<el-row>
			<el-col :span="12">

				<el-form-item label="雷达名称" prop="stationName">
					<el-input v-model="form.stationName" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="所属单位名" prop="affiliatedUnit">
					<el-input v-model="form.affiliatedUnit" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="类型" prop="type">
					<el-select v-model="form.type" size="default" placeholder="请选择" style="width: 190px" clearable
						filterable>
						<el-option label="军队" value="1" />
						<el-option label="地方" value="2" />
					</el-select>
				</el-form-item>

				<el-form-item label="功能描述" prop="functionDes">
					<el-input v-model="form.functionDes" style="width: 190px;" type="textarea" rows="6"></el-input>
				</el-form-item>

				<el-form-item label="探测距离" prop="detectionRange">
					<el-input v-model="form.detectionRange" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'detectionRange', 2)"></el-input>
				</el-form-item>

				<el-form-item label="威力范围" prop="powerRange">
					<el-input v-model="form.powerRange" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'powerRange', 2)"></el-input>
				</el-form-item>

				<el-form-item label="测距分辨率与精度" prop="ranging">
					<el-input v-model="form.ranging" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'ranging', 2)"></el-input>
				</el-form-item>
				<el-form-item label="测角分辨率与精度" prop="angulation">
					<el-input v-model="form.angulation" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'angulation', 2)"></el-input>
				</el-form-item>
				<el-form-item label="测速分辨率与精度" prop="velocity">
					<el-input v-model="form.velocity" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'velocity', 2)"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">

				<el-form-item label="工作频率" prop="frequency">
					<el-input v-model="form.frequency" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="功率" prop="power">
					<el-input v-model="form.power" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'power', 2)"></el-input>
				</el-form-item>
				<el-form-item label="品牌" prop="brand">
					<el-input v-model="form.brand" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="设备型号" prop="model">
					<el-input v-model="form.model" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="机器序列号" prop="serialNumber">
					<el-input v-model="form.serialNumber" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="生产厂家" prop="manufacturer">
					<el-input v-model="form.manufacturer" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="启用日期" prop="commissioningDate">
					<el-date-picker v-model="form.commissioningDate" size="default" type="date"
						value-format="YYYY-MM-DD" placeholder="请选择" style="width: 190px" />
				</el-form-item>

				<el-form-item label="报废日期" prop="dateOfRetirement">
					<el-date-picker v-model="form.dateOfRetirement" size="default" type="date" value-format="YYYY-MM-DD"
						placeholder="请选择" style="width: 190px" />
				</el-form-item>

			</el-col>
		</el-row>
		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>
	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface
	} from '@/api/common/common'

	import {
		regOnlyNumSpot
	} from '@/utils/reg'



	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData', 'stationCode'])

	const form = ref({
		stationCode: ''
	})

	const queryForm = ref('')


	//必填项
	const rules = reactive({
		name: [{
			required: true,
			message: "此选项不能为空!",
			trigger: "blur"
		}]
	})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/zhtx/radara/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}

	onMounted(() => {
		form.value.stationCode = props.stationCode
		if (props.editData) form.value = props.editData
	})
</script>

<style>
</style>